<extend name="Layout/ins_page" />
<block name="content">
	<input type="hidden" name="ajax" id="ajax" value="1">
	<select name="dept_list" id="dept_list" class="hidden">
		{:fill_option($dept_list)}
	</select>
	{:W('PageHeader/search',array('name'=>'用户管理','search'=>'S'))}
	<form method="post" id="form_adv_search" name="form_adv_search" method="post">
		<input type="hidden" name="ajax" id="ajax" value="1">
		<div class="operate panel panel-default">
			<div class="panel-body">
				<div class="pull-left form-inline">
					<label  for="eq_is_del"><b>状态:</b></label>
					<select id="eq_is_del" name="eq_is_del" class="col-10 form-control" onchange="submit_adv_search();">
						<option value="0">启用</option>
						<option value="1">禁用</option>
						<option value="2">其他</option>
					</select>
					<!--
						<a onclick="import_user()" class="hidden btn btn-sm btn-primary">导入</a>
						<a onclick="weixin_sync()" class="hidden btn btn-sm btn-primary">同步到微信</a>
					-->
					<a onclick="reset_pwd()" class="btn btn-sm btn-primary">设置密码</a>
					<!-- <a onclick="del_pwd()" class="btn btn-sm btn-primary">清空工资密码</a> -->
				</div>
				<div class="pull-right">
					<a onclick="add()"  class="btn btn-sm btn-primary">新增</a>
					<a onclick="save()"  class="btn btn-sm btn-primary">保存</a>
					|
					<a onclick="del()"  class="btn btn-sm btn-danger">删除</a>
				</div>
			</div>
		</div>
	</form>
	<div class="row">
		<div class="col-sm-4 sub_left_menu ">
			<form id="form_user" name="form_data" method="post" class="form-horizontal">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th class="text-center col-4">
								<label class="inline pull-left">
									<input class="ace" type="checkbox" name="id-toggle-all" id="id-toggle-all" />
									<span class="lbl"></span>
								</label>
							</th>
							<th>员工编号</th>
							<th>姓名</th>
							<th>状态</th>
						</tr>
					</thead>
					<tbody>
						<volist name="list" id="data">
							<tr id="{$data.id}" class="tbody">
								<td class="text-center col-3">
									<label class="inline pull-left click-inline">
										<input class="ace" type="checkbox" name="user_id[]" value="{$data.id}" />
										<span class="lbl"></span>
									</label>
								</td>
								<td class="click">{$data.emp_no}</td>
								<td class="click">{$data.name}</td>
								<td class="click">{$data.is_del|status}</td>
							</tr>
						</volist>
					</tbody>
				</table>
			</form>
			<div class="pagination">
				{$page}
			</div>
		</div>
		<div class="col-sm-8">
			<form id="form_data" name="form_data" method="post" class="form-horizontal">
				
				<input type="hidden" id="save_name" name="save_name"/>
				<input type="hidden" name="id" id="id" />
				<input type="hidden" name="pic" id="pic" />
				<input type="hidden" name="signature" id="signature" />
				<input type="hidden" name="opmode" id="opmode" value="edit" />
				<table class="table table-bordered" >
					<tr>
						<th class="col-10">
							<nobr>
								员工编号*
							</nobr>
						</th>
						<td colspan="2" class="col-30">
							<input class="form-control" type="text" id="emp_no" name="emp_no"  check="require" msg="请输入员工编号" readonly="readonly" />
						</td>
						<td rowspan="3" class="col-20">
							<img class="img-thumbnail col-12" id="emp_pic" onerror="javascript:this.src='/Uploads/emp_pic/no_avatar.jpg'" src="/Uploads/emp_pic/no_avatar.jpg"/>
						</td>
					</tr>
					<tr>
						<th>姓名*</th>
						<td colspan="2">
							<input class="form-control" type="text" id="name" name="name" class="input-sm" check="require" msg="请输入姓名" />
						</td>
					</tr>
					<tr>
						<th>性别</th>
						<td colspan="2">
							<select name="sex" id="sex" class="form-control col-10">
								<option  value="male">男</option>
								<option value="female">女</option>
							</select>
						</td>
					</tr>
					
					<tr>
						<th>状态</th>
						<td colspan="2">
							<select class="form-control col-10"  name="is_del" id="is_del">
								<option  value="0">启用</option>
								<option value="1">禁用</option>
							</select>
							<!--<input  type="text" id="birthday" name="birthday" readonly="readonly" class="input-date form-control" readonly="readonly">-->
						</td>
						<td colspan="2">
							<a onclick="select_avatar();" class="btn btn-sm btn-primary">上传头像</a>
						</td>
					</tr>
					<tr>
						<th>部门*</th>
						<td class="col-20">
						<div class="input-group ">
							<input class="form-control" name="dept_name"  id="dept_name" type="text" msg="请选择部门" check="require" readonly="readonly" />
							<input name="dept_id" id="dept_id" type="hidden" msg="请选择部门" check="require" />
							<div class="input-group-btn">
								<a class="btn btn-sm btn-primary" onclick="select_dept();" > <i class="fa fa-search" ></i> </a>
							</div>
						</div></td>
						<th class="col-10">职位*</th>
						<td>
							<select name="position_id" id="position_id" class="form-control" msg="请选择职位" check="require">
								<option value="">选择职位</option>
								{:fill_option($position_list)}
							</select>
						</td>
					</tr>
					<tr>
						<th>
							<nobr>
								办公室电话
							</nobr>
						</th>
						<td>
							<input type="text" id="office_tel" name="office_tel" class="form-control" />
						</td>
						<th>
							<nobr>
								移动电话
							</nobr>
						</th>
						<td>
							<input type="text" id="mobile_tel" name="mobile_tel" class="form-control" />
						</td>
					</tr>
					<tr>
						<th>电子邮箱</th>
						<td colspan="3">
							<input type="text" id="email" name="email" class="form-control" />
						</td>
					</tr>
					<tr>
						<th>
							<nobr>
								负责业务
							</nobr>
						</th>
						<td colspan="3">
							<input type="text" id="duty" name="duty" class="form-control" />
						</td>
					</tr>
					<tr>
						<th>状态</th>
						<td colspan="3">
							<select class="form-control col-10"  name="is_del" id="is_del">
								<option  value="0">启用</option>
								<option value="1">禁用</option>
							</select>
						</td>
					</tr>
					<tr>
						<td colspan="5">
							<p align="">
								带*为必填选项
							</p>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		function add() {
			winopen("{:U('add')}", 560, 470);
		};
		
		function del_pwd() {
			
			if ($("input[name='user_id[]']:checked").length == 0) {
				ui_error('请选择要清空密码的人员 ');
				return;
			}
			var vars = $("#form_user").serialize();
			ui_confirm('确定要清空密码吗?', function() {

				sendAjax("{:U('del_pwd')}", vars, function(data) {
					if (data.status) {
						ui_alert(data.info, function() {
							location.reload(true);
						});
					}
				});
			});
		}

		function del() {
			
			if ($("input[name='user_id[]']:checked").length == 0) {
				ui_error('请选择要删除的人员 ');
				return;
			}
			var vars = $("#form_user").serialize();
			ui_confirm('确定要删除吗?', function() {
				sendAjax("{:U('del')}", vars, function(data) {
					if (data.status) {
						ui_alert(data.info, function() {
							location.reload(true);
						});
					}
				});
			});
		}

		function reset_pwd() {
			if ($("#id").val().length < 1) {
				ui_error("请选择用户");
				return false;
			}
			winopen("{:U('password')}?id=" + $("#id").val(), 560, 470);
		}

		function import_user() {
			window.open("{:U('import')}", "_self");
			return false;
		}

		function select_dept() {
			winopen("{:U('dept/winpop2')}", 560, 470);
		}

		function weixin_sync() {
			winopen("{:U('weixin_sync')}",560, 470);
		}

		function select_avatar() {
			if ($("#id").val().length < 1) {
				ui_error("请选择用户");
				return false;
			}
			winopen("{:U('popup/avatar')}?id=" + $("#id").val(), 560, 470);
		}

		function select_signature() {
			if ($("#id").val().length < 1) {
				ui_error("请选择用户");
				return false;
			}
			winopen("{:U('popup/signature')}?id=" + $("#id").val(), 560, 470);
		}

		function btn_search() {
			sendForm("form_search", "__SELF__");
			$("#form_search").submit();
		}

		function key_search() {
			if (event.keyCode == 13) {
				sendForm("form_search", "__SELF__");
				return false;
			}
		}

		function save() {
			sendForm("form_data", "{:U('save')}");
		}

		function showdata(result) {
			$("#form_data select ").each(function() {
				$(this).find('option:first').attr('selected', 'selected');
			});
			for (var s in result.data) {
				set_val(s, result.data[s]);
			}
			$("#dept_name").val($("#dept_list option[value='" + $("#dept_id").val() + "']").text());
			img_url = $("#pic").val();
			if (img_url != "") {
				img_url += "?t=" + Math.random();
				$("#emp_pic").attr("src", img_url);
			} else {
				$("#emp_pic").attr("src", "/Uploads/emp_pic/no_avatar.jpg");
			}

			$("#save_name").val("");
			$("#opmode").val("edit");
		}


		$(document).ready(function() {
			set_return_url();
			set_val('eq_is_del', "{$eq_is_del}");
			$(".sub_left_menu tbody td.click").click(function() {
				$tr = $(this).parent();
				$(".sub_left_menu tbody tr.active").removeClass("active");
				$tr.addClass("active");
				sendAjax("{:U('read')}", "id=" + $tr.attr("id"), function(data) {
					showdata(data);
				});
				return false;
			});
			
			$('.click-inline').on('click','.ace',function(){
				$(this).parents('tr').find('td.click').trigger('click');
			})
		});
		
		

	</script>
</block>